﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TiTi.tea.Api.Models;
using TiTi.tea.BLL;
using TiTi.tea.Model;

namespace TiTi.tea.Api.Controllers
{
    [RoutePrefix("api/dictInfo")]
    public class DictInfoController : ApiController
    {
        private DictInfoBLL bll=new DictInfoBLL();

        [Route("Query")]
        [HttpGet]
        public Result Query(string DictName,int PageSize,int PageIndex) 
        {
            int total = 0;
            var data = bll.Query(DictName,out total, PageSize, PageIndex);
            return Result.Success(new {data,total });
        }
        [Route("Get")]
        [HttpGet]
        public Result Get(int id)
        {
            var data = bll.Get(id);
            return Result.Success(data);
        }
        [Route("Add")]
        [HttpPost]
        public Result Add(DictInfo entity) 
        {
        entity.CreateTime = DateTime.Now;
            entity.IsDelete = 0;
            if (bll.Add(entity))
            {
                return Result.Success(entity);
            }
            else 
            {
                return Result.Error("添加失败");
            }
        }
        public Result Update(DictInfo entity)
        {
            DictInfo dictInfo = bll.Get(entity.Id);
            dictInfo.DictName = entity.DictName;

            if (bll.Update(dictInfo))
            {
                return Result.Success(dictInfo);
            }
            else
            {
                return Result.Error("修改失败");
            }
        }
        public Result Delete(int id)
        {
            return Result.Success(bll.Delete(id));
        }
    }
}
